home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntc6846.zoo / patch / sftoul.s < prev    next >
Encoding:
Text File  |  1994-11-14  |  2.5 KB  |  75 lines

  1.  ! C68 floating point => 32 bit unsigned conversion routines
  2.  !-----------------------------------------------------------------------------
  3.  ! ported to 68000 by Kai-Uwe Bloem, 12/89
  4.  !  #1  original author: Peter S. Housel 6/12/89,6/14/89
  5.  !  #2  replaced shifts by swap if possible for speed increase -kub-, 01/90
  6.  !  #3  Added wrapper routine to provide C68 IEEE support
  7.  !                                             Dave & Keith Walker     02/92
  8.  !  #4    Changed entry/exit code for C68 v4.3 compatibility
  9.  !    Removed ACk entry points                    09/93
  10.  !-----------------------------------------------------------------------------
  11.  
  12. BIAS4  =       0x7F - 1
  13.  
  14.        .sect .text
  15.  
  16.        .define .Xsftoul
  17.  
  18. !----------------------------------------
  19. !      sp      Return address
  20. !      sp+4    address of float/double
  21. !----------------------------------------
  22. .Xsftoul:
  23.        move.l  4(sp),a0        ! address of value
  24.        move.w  (a0),d0         ! extract exp
  25.        move.w  d0,d2           ! extract sign
  26.        lsr.w   #7,d0           ! shift down 7
  27.        and.w   #0x0ff,d0       ! kill sign bit
  28.  
  29.        cmp.w   #BIAS4,d0       ! check exponent
  30.        blt     zer4            ! strictly fractional, no integer part ?
  31.        cmp.w   #BIAS4+32,d0    ! is it too big to fit in a 32-bit integer ?
  32.        bgt     toobig
  33.  
  34.        move.l  (a0),d1
  35.        and.l   #0x7fffff,d1    ! remove exponent from mantissa
  36.        or.l    #0x800000,d1    ! restore implied leading "1"
  37.  
  38.        sub.w   #BIAS4+24,d0    ! adjust exponent
  39.        bgt     2f              ! shift up
  40.        beq     3f              ! no shift
  41.  
  42.        cmp.w   #-8,d0          ! replace far shifts by swap
  43.        bgt     1f
  44.        clr.w   d1              ! shift fast, 16 bits
  45.        swap    d1
  46.        add.w   #16,d0          ! account for swap
  47.        bgt     2f
  48.        beq     3f
  49.  
  50. 1:     lsr.l   #1,d1           ! shift down to align radix point;
  51.        add.w   #1,d0           ! extra bits fall off the end (no rounding)
  52.        blt     1b              ! shifted all the way down yet ?
  53.        bra     3f
  54.  
  55. 2:     add.l   d1,d1           ! shift up to align radix point
  56.        sub.w   #1,d0
  57.        bgt     2b
  58.        bra     3f
  59. zer4:
  60.        clr.l   d1              ! make the whole thing zero
  61. 3:     move.l  d1,d0
  62.        tst.w   d2              ! is it negative ?
  63.        bpl     8f
  64.        neg.l   d0              ! negate
  65.  
  66. 8:    move.l    (sp)+,a1    ! get return address
  67.     add.l    #4,sp        ! remove one parameter from stack
  68.     jmp    (a1)        ! return to caller
  69.  
  70. toobig:
  71.     jsr    .overflow
  72.     move.l    #0xffffffff,d0    ! set ULONG_MAX as reply
  73.     bra    8b
  74.  
  75.